package com.xayy.health.core.enums;

import lombok.Getter;

/**
 * cron类型枚举
 *
 * @author houchengwei
 * createTime 2023/2/20
 * @version V1.0
 */
public enum CronTypeEnum {
    //每隔24小时执行一次
    TWENTY_FOUR_HOUR(1, "* * 0/24 * * ? ", "每隔24小时执行一次"),
    //每隔10S执行一次
    ONE_HOUR(2, "0/10 * * * * ? ", "每隔10S执行一次");

    @Getter
    private Integer code;
    @Getter
    private String name;
    @Getter
    private String rule;

    CronTypeEnum(Integer code, String name, String rule) {
        this.code = code;
        this.name = name;
        this.rule = rule;
    }

    public static String valueof(Integer index) {
        for (CronTypeEnum relationTypeEnum : values()) {
            if (relationTypeEnum.getCode().equals(index)) {
                return relationTypeEnum.name;
            }
        }
        return "";
    }

    public static String getRule(Integer index) {
        for (CronTypeEnum relationTypeEnum : values()) {
            if (relationTypeEnum.getCode().equals(index)) {
                return relationTypeEnum.rule;
            }
        }
        return "";
    }
}
